package farmer.render.building;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;

import farmer.core.Building;
import farmer.core.Doodad;
import farmer.core.Unit;

public class Map extends farmer.update.building.Map{

	public Map(int sizeX, int sizeY) {
		super(sizeX, sizeY);
	}
	
	private BasicStroke gridStroke = new BasicStroke(1);
	private BasicStroke borderStroke = new BasicStroke(18);
	
	public void draw(Graphics2D g){
		//DrawBorder
		g.setColor(Color.black);
		g.setStroke(borderStroke);
		g.drawRect(-8, -8, sizeX*cellWidth+16, sizeY*cellWidth+16);
		//Draw the terrain
		for(int i=0; i<getSizeX(); i++){
			for(int j=0; j<getSizeY(); j++){
				int type = getTerrain(i, j);
				g.setColor(getColor(type));
				g.fillRect(i*cellWidth, j*cellWidth, cellWidth, cellWidth);
			}
		}
		//Draw road
		for(int i=0; i<buildingList.size(); i++){
			Building building = buildingList.get(i);
			if(building instanceof Road){
				building.draw(g);
			}
		}
		//Draw the grid
		g.setColor(Color.black);
		g.setStroke(gridStroke);
		for(int i=0; i<getSizeX(); i++){
			g.drawLine(i*cellWidth, 0, i*cellWidth, getSizeY()*cellWidth);
		}
		for(int j=0; j<getSizeX(); j++){
			g.drawLine(0, j*cellWidth, getSizeX()*cellWidth, j*cellWidth);
		}
		//Draw doodad
		for(int i=0; i<doodadList.size(); i++){
			Doodad doodad = doodadList.get(i);
			doodad.draw(g);
		}
		//Draw building
		for(int i=0; i<buildingList.size(); i++){
			Building building = buildingList.get(i);
			if(!(building instanceof Road)){
				building.draw(g);
			}
		}
		theCity.draw(g);
		//Draw unit
		for(int i=0; i<unitList.size(); i++){
			Unit unit = unitList.get(i);
			unit.draw(g);
		}
	}
	
	private final int GRASS = 0;
	//private Color grass = new Color(95, 211, 24);
	private Color grass2 = new Color(68, 150, 35);
	private Color getColor(int type){
		if(type == GRASS){
			return grass2;
		}
		return null;
	}

}
